package com.cskaoyan.shopping.service.impl;

import com.cskaoyan.mall.commons.exception.ExceptionProcessorUtils;
import com.cskaoyan.shopping.converter.CategoryConverter;
import com.cskaoyan.shopping.dal.entitys.Category;
import com.cskaoyan.shopping.dal.persistence.CategoryMapper;
import com.cskaoyan.shopping.dto.CategoryDto;
import com.cskaoyan.shopping.dto.CategoryResponse;
import com.cskaoyan.shopping.service.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description:
 * @Author llf
 * @Date 2022/6/18 18:33
 */
@Service
public class ICategoryServiceImpl implements ICategoryService {
    @Autowired
    CategoryMapper categoryMapper;
    @Autowired
    CategoryConverter categoryConverter;
    @Override
    public CategoryResponse categoryPage(String sort) {
        CategoryResponse categoryResponse = new CategoryResponse();
        try {
            List<Category> categories = categoryMapper.selectAllAndOrder();

            List<CategoryDto> categoryDtos = categoryConverter.ListCategoryToDto(categories);
            categoryResponse.setCode("000000");
            categoryResponse.setMsg("成功");
            categoryResponse.setCategoryDtos(categoryDtos);
        } catch (Exception e) {
            e.printStackTrace();
            ExceptionProcessorUtils.wrapperHandlerException(categoryResponse, e);
        }
        return categoryResponse;
    }}



